﻿/*
This file is under Microsoft Public License (MS-PL)
Copyright Yohann MARTEL.  All rights reserved.
Codeplex: http://amf.codeplex.com
AMF Website: http://www.ymartel.com/aspnet-mobile-framework/
*/
using System;
using System.Collections.Generic;
using System.Web.UI;

namespace Mobile
{
    /// <summary>
    /// Helper for the generation of the attribute class 
    /// </summary>
    internal class CssClassGenerator
    {
        private List<string> classList; 

        public CssClassGenerator()
        {
            classList = new List<string>();
        }

        public void AddCssClass(string className)
        {
            classList.Add(className);
        }

        public string GetCssClass()
        {
            string cssClass = String.Empty;
            bool isFirst = true;
            foreach (string className in classList)
            {
                if (!isFirst)
                {
                    cssClass += " ";
                }
                else
                {
                    isFirst = false;
                }
                cssClass += className;

            }
            return cssClass;
        }

        public void RenderCssClass(HtmlTextWriter writer)
        {
            string cssClass = GetCssClass();
            if (!String.IsNullOrEmpty(cssClass))
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Class, cssClass);
            }
        }
    }
}
